This is how we started: let guests = ["ANTONY", "CICERO", "CASSIUS", "CLEOPATRA"];
Caesar remembers he forgot to add his best friend "BRUTUS" to the list. Add him to the beginning of the list.
guests.unshift("BRUTUS")
How can you verify that "BRUTUS" was added to the beginning of the array?
guests[0]
HA herald announced the arrival of "AUGUSTUS" and "LUCIA". Add them to the end of the guest list.
guests.push("AUGUSTUS", "LUCIA")
Caesar is curious. He wants to know if "SPARTACUS" has been invited. Check if he's on the list and find out at which position.
let ifSpartacusInvited = guests.indexOf("SPARTACUS") //if "SPARTACUS" is not present the value will bee "-1"
Oops! Caesar just received a message that "CASSIUS" won't be able to make it. Remove him from the list.
const index = guests.indexOf("CASSIUS");
if (index !== -1) {
guests.splice(index, 1);
} // then I check the answher and saw, that it should work in different way, so I remade it in other way and think it's much better:
guests.splice(guests.indexOf("CASSIUS"), 1)
Caesar wants to send a special invite to the first three guests on the list. Extract these names into a new array.
let newListFirstThree = guests.slice(0, 3); //Tryied to do slice(0,2), watched video again and this index of second argument is really strange xD
Caesar decides he wants the guest list in alphabetical order. Sort the array. However, Caesar wants his most honored guest (the one added first) to remain at the top of the list. Can you think of a way to sort the guests but keep the honored ones at the top?
guests = [guests[0], ...guests.slice(1).sort()]
//I didn't like method provided by springboard, I though that the best way would be just sort all the list ignoring the index[0] wich is "BRUTUS". I googled and found the " . . ." part- that perfectly fits my idea. But it requere guests not to be a const -> it should be let (variable), so I changed the first announce of guests (why not, hm?!)